package com.loren.designer.web.controller;

import com.loren.designer.data.dto.ScreenDto;
import com.loren.designer.data.form.QueryForm;
import com.loren.designer.data.form.ScreenForm;
import com.loren.designer.data.resp.MPage;
import com.loren.designer.data.resp.SuccessResponse;
import com.loren.designer.service.ScreenService;
import com.fasterxml.jackson.annotation.JsonView;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@AllArgsConstructor
@RequestMapping("/screen")
public class ScreenController {

    private final ScreenService screenService;

    @GetMapping("/list")
    @JsonView(ScreenDto.ScreenListView.class)
    public MPage<ScreenDto> screenInfoList(@Validated QueryForm form) {
        return this.screenService.getScreenInfoList(form);
    }

    @GetMapping("/{id}")
    public ScreenDto screenInfo(@PathVariable("id") String screenId) {
        return this.screenService.getScreenInfo(screenId);
    }

    @PostMapping("/save")
    public SuccessResponse saveScreenInfo(@RequestBody @Validated ScreenForm form) {
        this.screenService.saveScreenInfo(form);
        return SuccessResponse.success();
    }

    @PostMapping("/status")
    public SuccessResponse changeScreenStatus(@RequestParam("id") String screenId) {
        this.screenService.changeScreenStatus(screenId);
        return SuccessResponse.success();
    }

    @PostMapping("/delete")
    public SuccessResponse deleteScreenInfo(@RequestParam("id") String screenId) {
        this.screenService.deleteScreenInfo(screenId);
        return SuccessResponse.success();
    }
}
